package com.neo.web.config;

import com.neo.web.beans.Result;
import com.neo.web.beans.ResultCode;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalArgumentException.class)
    public Result<?> exceptionHandler(IllegalArgumentException e, HttpServletRequest request) {
        log.error("Global exception: {} [uri: {}] [query: {}]",
                e.getMessage(),
                request.getRequestURI(),
                request.getQueryString(),
                e);
        return Result.of(ResultCode.FAIL);
    }

}
